package com.afu.aopDemo.aop;

import com.afu.aopDemo.annotion.log;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * ClassName: MyAspect
 * Package: com.afu.aopDemo.aop
 * Description:
 *
 * @Author zxf
 * @Create 2024/2/2 12:31
 * @Version 1.0
 */
@Aspect
@Component
public class MyAspect {

    @Pointcut("execution(* com.afu.aopDemo.service..*(..))")
    public void pointCut(){

    }

    @Around("pointCut()")
    public Object method(ProceedingJoinPoint point) throws Throwable {
        Signature signature = point.getSignature();
        System.out.println(signature.getDeclaringType());
        //将目标方法的签名对象转化为MethodSignature
        MethodSignature methodSignature= (MethodSignature) signature;
        //获得方法的注解
        Method method = methodSignature.getMethod();
        log annotation = method.getAnnotation(log.class);
        String value = annotation.value();
        System.out.println(value);
        Object proceed = point.proceed();
        System.out.println(proceed);
        return proceed;
    }


}
